package main

import (
	"encoding/json"
	"fmt"
)

type Person map[string]interface{}

func main() {
	js:=`{"id":1,"name":"hello"}`
	fmt.Printf("%+v\n",NamedSuccess(js))//map[id:1 name:hello]
	fmt.Printf("%+v\n",NamedWithBug(js))//<nil>
}

func NamedSuccess(jsonString string) (person Person) {//person置零，没有进行初始化，map零值为nil
	fmt.Printf("%#v\n",person)//main.Person(nil)
	json.Unmarshal([]byte(jsonString),&person)//因为person为有效结构体，可以取地址
	return
}

func NamedWithBug(jsonString string) (person *Person) {//*person为指针，也是置零，指针为零值nil
	fmt.Printf("%#v\n",person)//(*main.Person)(nil)
	err := json.Unmarshal([]byte(jsonString), person)
	if err != nil {
		fmt.Println("err:",err)//err: json: Unmarshal(nil *main.Person)
	}
	return
}
